#encoding:gbk

import pandas as pd
import numpy as np
import talib
import datetime
import time

def init(ContextInfo):
	#hs300成分股中sh和sz市场各自流通市值最大的前3只股票
	fieldList = ['CAPITALSTRUCTURE.total_capital', '利润表.净利润']
	index_universe = ['000991.SH'] 
	index_stocks = []
	for index in index_universe:
		#print(index)
		for stock in ContextInfo.get_sector(index):
			stock_Name = ContextInfo.get_stock_name(stock)
			#print(stock+':'+stock_Name)
			index_stocks.append(stock)
	ContextInfo.startDate = '20210101'
	ContextInfo.endDate = '20210331'
	ContextInfo.index_stocks=['600460.SH']
	ContextInfo.fieldList = ['资产负债表.固定资产', '利润表.净利润']	
	print('init end')
	
	
def handlebar(ContextInfo):
	if ContextInfo.is_last_bar():
		print(ContextInfo.index_stocks)
		#取总股本和净利润
	
		#financial_data=ContextInfo.get_financial_data(ContextInfo.fieldList, ContextInfo.index_stocks, ContextInfo.startDate, ContextInfo.endDate,report_type = 'report_time')
		index = ContextInfo.barpos
		financial_data=ContextInfo.get_financial_data('ASHAREBALANCESHEET','fix_assets','SH','600000',index)
		
		print(financial_data)
		print('handlebar end')


